﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace PowerCreator.LMS.WebPage.Comment
{
   public partial class AddCommentNew :PowerCreator.LMS.Web.Base.BasePage

    //public partial class AddCommentNew : System.Web.UI.Page
    {
        PowerCreator.LMS.Web.Comment.Comment commentManager = new PowerCreator.LMS.Web.Comment.Comment();
        string url = "AddCommentNew.aspx";
        string rid = "0";
        string cid = "0";
        protected string courseID = "0";
        protected string classID = "0";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["UserID"] = GetCreatedByInfo().UserID;
                if (Session["TG_ResourceID"] != null)
                {
                    rid = Session["TG_ResourceID"].ToString();
                    ViewState["ResourceID"] = rid;
                }
                if (Request.Params["CourseID"] != null)
                {
                    courseID = Request.QueryString["CourseID"].ToString();
                    ViewState["CourseID"] = courseID;
                }
                if (Request.QueryString["ClassID"] != null)
                {

                    classID = Request.QueryString["ClassID"].ToString();
                    ViewState["ClassID"] = classID;
                }
                if (Request.Params["ContentID"] != null)
                {
                    cid = Request.QueryString["ContentID"].ToString();
                    ViewState["ContentID"] = cid;
                }

                if (Request.Params["position"] != null)
                {
                    string Playtime = Request.QueryString["position"].ToString();
                    ViewState["position"] = Playtime;
                }
                string Content = Request.QueryString["filter"].ToString();
                ViewState["Content"] = Content;
                //ViewState["PlayTime"] = playtime.ToString();

                ADD();
            }
        }

       void ADD()
       {
           if (ViewState["ResourceID"] == null && ViewState["ContentID"]==null)
           {

               string msg = "参数传递错误，请检查!";
               PowerCreator.LMS.Common.Script.Script.ShowAndReload(msg, url);
               return;
           }

           PowerCreator.LMS.Grade.Entity.VOTGrade vo = new PowerCreator.LMS.Grade.Entity.VOTGrade();
           PowerCreator.LMS.Web.Grade.GradeManager op = new PowerCreator.LMS.Web.Grade.GradeManager();
           if (ViewState["ResourceID"] != null )
           {

               vo.FKGradeResourceID = int.Parse(ViewState["ResourceID"].ToString()); 
           }
           if (ViewState["ContentID"] != null)
           {

               vo.FKGradeContentGuid = ViewState["ContentID"].ToString();
           }

           
           vo.FKGradeSkillID = 0;
           vo.FKCourseID = int.Parse(ViewState["CourseID"].ToString());
           vo.FKClassid = int.Parse(ViewState["ClassID"].ToString());
           //vo.FKGradeUserID=int.Parse(Session["UserID"].ToString());
           vo.FKGradeUserID = int.Parse(ViewState["UserID"].ToString());
           int playtime = 0;
           if (ViewState["position"] != null)
               playtime = int.Parse(ViewState["position"].ToString());
           vo.GradeAsfTime = playtime;
           vo.GradeContent = ViewState["Content"].ToString();
           vo.GradeCreatetime = DateTime.Now;
           vo.GradeScore = 0;
           if (op.AddGrade(vo))
           {
               Response.Write("1");
           }
           else
           {
               Response.Write("0");
           }
           Response.End();
           
           //PowerCreator.LMS.Common.Script.Script.CloseMe();
           //string urlnew="AddCommentNew.aspx?ResourceID="+ViewState["ResourceID"].ToString();
           //PowerCreator.LMS.Common.Script.Script.RedirectNewUrl(urlnew);
       }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            ADD();
        }
         
    }
}
